package com.example.springinitialization.exception;

import com.example.springinitialization.constant.ErrorCode;
import lombok.Data;

/**
 * 自定义异常注解类
 */
@Data
public class MyException extends RuntimeException {

    private String msg;
    private int code = 1;

    public MyException() {
        super();
    }

    public MyException(int code, String message) {
        super(message);
        this.code = code;
        this.msg = message;
    }

    public MyException(String message) {
        super(message);
        this.msg = message;
    }

    public MyException(ErrorCode errorCode) {
        this.msg = errorCode.getMessage();
        this.code = errorCode.getCode();
    }

    public MyException(ErrorCode errorCode, String message) {
        this.msg = message;
        this.code = errorCode.getCode();
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return msg;
    }
}
